/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.processing.base.mapreduce;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.WritableComparable;

/**
 *
 * @author nastya
 */
public class UserArtistKey implements WritableComparable<UserArtistKey> {
    byte[] user;
    byte[] artist;
    byte[] key;

    public byte[] getArtist() {
        return artist;
    }

    public byte[] getUser() {
        return user;
    }

    public byte[] getKey() {
        return key;
    }

    public UserArtistKey() {
    }

    public UserArtistKey(byte[] user, byte[] artist, byte[] key) {
        this.user = user;
        this.artist = artist;
        this.key = key;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        String userS = Bytes.toString(user);
        String artistS = Bytes.toString(artist);
        String tst = Bytes.toString(key);
        out.writeUTF(tst);
        out.writeUTF(userS);
        out.writeUTF(artistS);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        String keyL = in.readUTF();
        String userS = in.readUTF();
        String artistS = in.readUTF();
        this.key = Bytes.toBytes(keyL);
        this.user = Bytes.toBytes(userS);
        this.artist = Bytes.toBytes(artistS);
    }

    @Override
    public int compareTo(UserArtistKey t) {
        if (t == null) {
            return 1;
        }
        String a1 = Bytes.toString(artist);
        String a2 = Bytes.toString(t.artist);
        return a1.compareTo(a2);
    }
    
}
